<template>
    <div class="list-page">
        <tool-bar nav="" title="工作流">
            <el-button @click="add_click()">添加</el-button>
        </tool-bar>
        <my-list
            ref="list"
            :url='wf_host + "/wf/list"'
            @param="preload"
            @loaded="procData"
            :page-size="10"
            :store="true"
        >

            <el-table-column label="部署id" align="center">
                <template v-slot="scope">
                    <div class="link" @click="edit_click(scope.row)">{{ scope.row.deployId }}</div>
                </template>
            </el-table-column>
            <el-table-column prop="name" label="工作流程名" align="center"></el-table-column>
            <el-table-column prop="category" label="分类" align="center"></el-table-column>
            <el-table-column prop="deployTime" label="部署时间" align="center"></el-table-column>
            <el-table-column prop="startName" label="启动人" align="center"></el-table-column>
            <el-table-column prop="count" label="任务数" align="center"></el-table-column>
            <el-table-column label="操作" align="center" width="240">
                <template v-slot="scope">
                    <el-button @click="start(scope.row)" type="primary" size="small">启动</el-button>
                  <el-button type="warning" plain round @click="delete_click(scope.row)" size="small">删除</el-button>
                </template>
            </el-table-column>
            <template #query="scope">
                <kv label="名称">
                    <el-input v-model="scope.query.name"></el-input>
                </kv>
                <kv label="工作流分类">
                    <el-input v-model="scope.query.category"></el-input>
                </kv>
            </template>
        </my-list>
    </div>
</template>

<script setup>
/**
 * Created by CodeGenerator at 2021-03-15 10:31:23
 */





//定义 vue2的this,当前组件
const $self = getCurrentInstance();

//定义 $attrs
const $attrs = useAttrs();



//定义data
const $data = reactive({"pageSize":10});


const $props = defineProps({

});





const list = ref();

//定义事件
const $emit = defineEmits(["update:modelValue","loaded"]);



const preload = function(param) {
//添加查询参数，修改分页参数等。
//param.type = jv.$route.params.type
    param.pageNo = param.pageNumber;
    param.pageSize = param.take;
    param.query = {
        name: param.name,
        category: param.category,
    }
};
const procData = function(res) {
    res.data.data.forEach(it => {
//如果是组合实体，设置 it.id=...
        it.roles_res = (it.roles || []).map(it => it.name).join(",")
        it.id = it.deployId;
    });
};
const loadData = function(pageNumber) {
    list.value.loadData(pageNumber);
};
const add_click = function() {
    jv.$router.push("/demo/activiti/add")
};
const edit_click = function(row) {
//记录上次点击行
    var rowId = row.id;
    list.value.setLastRow(row);
    jv.$router.push("/demo/activiti/edit/" + rowId)
};
const delete_click = function(row) {
    var rowId = row.id;
    var rowName = row.name;
    jv.confirm('确认删除 ' + rowName + ' 吗？').then(res => {
        jv.$http.post($data.wf_host + "/wf/delete?id=" + rowId).then(res => {
//[axios拦截器中已处理了异常]。
            loadData();
        })
    });
};
const start = function(row) {
    jv.prompt("输入任务名称", "名称", {inputValue: jv.me.user.name + "-请假单"}).then(res => {
        var taskName = res.value
        if (!taskName) return;
        jv.$http.post($data.wf_host + "/wf/start?id=" + row.deployId + "&name=" + taskName + "&loginName=" + jv.me.user.loginName)
            .then(res => {
                this.$notify({
                    title: "流程启动成功",
                    type: "success"
                });
                loadData();
            });
    })
};
</script>
